package cn.wolfcode.controller;

import cn.wolfcode.domain.Travel;
import cn.wolfcode.query.QueryObject;
import cn.wolfcode.query.TravelQueryObject;
import cn.wolfcode.service.IDestinationService;
import cn.wolfcode.service.ITravelService;
import cn.wolfcode.util.JsonResult;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @Description: 区域控制器类
 * @Author: 伍家钰
 * @Date: 2020/8/10 10:40
 * @Version: 1.0
 */
@Controller
@RequestMapping("travel")
public class TravelController {
    @Resource
    private ITravelService travelService;
    @Resource
    private IDestinationService destinationService;

    /**
     * 分页查询
     *
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") TravelQueryObject qo) {
        Page<Travel> page = travelService.query(qo);
        model.addAttribute("page", page);
        return "travel/list";
    }

    /**
     * 游记审核
     *
     * @param id
     * @param state
     * @return
     */
    @RequestMapping("audit")
    @ResponseBody
    public Object audit(String id, int state) {
        travelService.audit(id, state);
        return JsonResult.success();
    }

    /**
     * 游记下架
     *
     * @param id
     * @param state
     * @return
     */
    @RequestMapping("updateState")
    @ResponseBody
    public Object updateState(String id, int state) {
        return travelService.updateState(id, state);

    }

    /**
     * 后台游记管理中查看游记内容
     *
     * @param id
     * @return
     */
    @RequestMapping("getContentById")
    @ResponseBody
    public Object getContentById(String id) {
        String content = travelService.getContentById(id);
        return JsonResult.success(content);
    }


}
